﻿@{
    // these need to be in the head because MediaBrowser.js defines a callback that the thumbnail images call when they load,
    // which could happen as soon as they render.
    Style.Require("jQueryUI_Orchard").AtHead();
    Script.Require("jQueryUI_Tabs").AtHead();

    SetMeta("X-UA-Compatible", "IE=edge,chrome=1");
    Style.Include("~/themes/theadmin/styles/site.css");
	Style.Include("~/themes/theadmin/styles/ie.css").UseCondition("lte IE 8").SetAttribute("media", "screen, projection");
	Style.Include("~/themes/theadmin/styles/ie6.css").UseCondition("lte IE 6").SetAttribute("media", "screen, projection");

    Script.Include("ContentPicker.js");
    Style.Include("ContentPicker.css");
    
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>@T("Select Content Item")</title>
    @Display.Metas()
    @Display.HeadScripts()
    @Display.HeadLinks()
    @Display.StyleSheetLinks()
</head>
<body id="orchard-content-picker">

    <script type="text/javascript">
        $.extend({
            contentPicker: {}
        });
            
        $.contentPicker.cannotPerformMsg="@T("Cannot perform requested operation")";
        $.contentPicker.accessDeniedMsg="@T("Authentication timed-out: please log-on again")";
        $.contentPicker.logonUrl="@Url.Action("LogOn", new { Controller = "Account", Area = "Orchard.Users" })";
    </script>

    @Display.ContentPickerNavigation()
    
    <div class="content-picker-tab">
    @Display(Model.Tab)
    </div>

@using(Script.Foot()) {
<script type="text/javascript">
//<![CDATA[
    $(".select").on("click", function () {
        try {
            var container = $(this).closest("[data-id]");
            var result = {
                id: container.attr("data-id"),
                displayText: container.attr("data-display-text"),
                editLink: container.attr("data-edit-link"),
                displayLink: container.attr("data-display-link")
            };

            window.opener.jQuery[query("callback")](result);
        } catch (ex) {
            alert($.contentPicker.cannotPerformMsg);
            alert(ex);
        }
        window.close();
    });

    $("ul a").each(function () {
        var self = $(this);
        var link = self.attr("href");
        // if the link doesn't define the "callback" query string, then append it
        // n.b., pagers already append it
        if (query("callback", link).length == 0) {
            link = link + "?callback=" + query("callback");
            self.attr("href", link);
        }
    });
    
    // get a querystring value
    function query(name, querystring) {
        name = name.toLowerCase();
        var search = querystring || location.search;
        var parts = search.replace("?", "").replace("#", "").split("&");
        for (var i = 0, l = parts.length; i < l; i++) {
            var part = parts[i];
            var eqIndex = part.indexOf("=");
            if (eqIndex !== -1 && part.substr(0, eqIndex).toLowerCase() === name) {
                return part.substr(eqIndex + 1);
            }
        }
        return null;
    }
//]]>
</script>
}

    @Display.FootScripts()
</body>
</html>
